using System;
using System.Collections;
using System.Text;

using Qiang.Topology.Geometries;

namespace Qiang.Topology.Operation.Valid
{
    /// <summary>
    /// 
    /// </summary>
    public enum TopologyValidationErrors
    {     
        /// <summary>
        /// 
        /// </summary>
        Error                   = 0,

        /// <summary>
        /// 
        /// </summary>
        RepeatedPoint           = 1,

        /// <summary>
        /// 
        /// </summary>
        HoleOutsideShell        = 2,

        /// <summary>
        /// 
        /// </summary>
        NestedHoles             = 3,

        /// <summary>
        /// 
        /// </summary>
        DisconnectedInteriors   = 4,

        /// <summary>
        /// 
        /// </summary>
        SelfIntersection        = 5,

        /// <summary>
        /// 
        /// </summary>
        RingSelfIntersection    = 6,

        /// <summary>
        /// 
        /// </summary>
        NestedShells            = 7,

        /// <summary>
        /// 
        /// </summary>
        DuplicateRings          = 8,

        /// <summary>
        /// 
        /// </summary>
        TooFewPoints            = 9,

        /// <summary>
        /// 
        /// </summary>
        InvalidCoordinate       = 10,
    }

    /// <summary>
    /// Contains information about the nature and location of a <c>Geometry</c>
    /// validation error.
    /// </summary>
    public class TopologyValidationError 
    {
        // NOTE: modified for "safe" assembly in Sql 2005
        // Added readonly!

        /// <summary>
        /// These messages must synch up with the indexes above
        /// </summary>
        private static readonly string[] errMsg = 
        {
            "Topology Validation Error",
            "Repeated Point",
            "Hole lies outside shell",
            "Holes are nested",
            "Interior is disconnected",
            "Self-intersection",
            "Ring Self-intersection",
            "Nested shells",
            "Duplicate Rings",
            "Too few points in geometry component",
            "Invalid Coordinate"
        };

        private TopologyValidationErrors errorType;
        private Coordinate pt;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="errorType"></param>
        /// <param name="pt"></param>
        public TopologyValidationError(TopologyValidationErrors errorType, Coordinate pt)
        {
            this.errorType = errorType;
            this.pt = (Coordinate) pt.Clone();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="errorType"></param>
        public TopologyValidationError(TopologyValidationErrors errorType) : this(errorType, null) { }

        /// <summary>
        /// 
        /// </summary>
        public virtual Coordinate Coordinate
        {
            get
            {
                return pt;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual TopologyValidationErrors ErrorType
        {
            get
            {
                return errorType;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual String Message
        {
            get
            {
                return errMsg[(int)errorType];
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Message + " at or near point " + pt;
        }
    }
}
